package com.fallsvc.re.networkprogramming.file.output;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @auther falls_vc
 * description:
 * @date 2025/11/3  16:01
 */
public class Demo1 {
    public static void main1(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("output.txt")) {
            os.write('H');
            os.write('e');
            os.write('l');
            os.write('l');
            os.write('o');
// 不要忘记 flush
//            os.flush();
        }
    }
    public static void main2(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("output.txt")) {
            byte[] b = new byte[] {
                    (byte)'G', (byte)'o', (byte)'o', (byte)'d', (byte)'B', (byte)'a'
            };
            os.write(b, 0, 4);
// 不要忘记 flush
            os.flush();
        }
    }
    public static void main(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("output.txt")) {
            String s = "Nothing";
            byte[] b = s.getBytes();
            os.write(b);
// 不要忘记 flush
            os.flush();
        }
        try (OutputStream os = new FileOutputStream("output.txt")) {
            String s = "你好中国";
            byte[] b = s.getBytes("utf-8");
            os.write(b);
// 不要忘记 flush
            os.flush();
        }
    }
}
